package com.cbz.learn.kafka;

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.CreateTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 测试创建数据
 */
public class AdminTopicTest {

    public static void main(String[] args) {
        Map<String, Object> confMap = new HashMap<>();
        // 配置kafka连接地址
        confMap.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");

        // 管理员对象
        final Admin admin = Admin.create(confMap);

        // 构建主题 三个参数分别为：主题名称，分区数量，副本数量
        NewTopic topic01 = new NewTopic("test01", 1, (short) 1);

        NewTopic topic02 = new NewTopic("test02", 2, (short) 2);

        CreateTopicsResult topics = admin.createTopics(Arrays.asList(topic01, topic02));

        admin.close();
    }
}
